/**
 *
 *  Project      :  UVa's acm
 *  Project site :  code.google.com/p/uvaacm/
 *  Author       :  Ives Liao
 *  E-Mail       :  iveslazycat at gmail.com
 *  Date         :  2011/11/17
 *  Website      :  iveslazycat.pixnet.net
 *  
 */
#ifdef ONLINE_JUDGE /* If compiler is UVa's online judge */
    #include<stdio.h> /*Include standard header foe UVa's compiler */
    #include<stdlib.h>
    #include<math.h>
    #define INPUT stdin /* Define the input is from standard input */
#else
    #include"header.h" /* Include my own header */
    #define INPUT fptIn /* Define the input is from input file */
#endif
/*---------- Do sub function declare below here \/----------*/
unsigned int reverseInt(unsigned int num);
int isAnagram(unsigned int num);
/*---------- Do sub function declare above here /\----------*/
#ifdef ONLINE_JUDGE
	int main() {/* main() for UVa's online judge */
#else
    int acm_10018() {/* function name for my own */
        printf("--acm_10018 begin here--\n");/* Print begining of problem */
        FILE *fptIn = fopen("Resource/acm_10018.txt","r");/* Open input file to test */
        if ( fptIn == NULL )/* Distinguish the fptInIn file is load success. */
        {
            printf("File acm_10018.txt load fail.\n");/* Telling user file loading failed. */
            printf("Program will exit.\n");/* Telling user function gonna end. */
            return EXIT_FAILURE;/* Return to problem selector(main) */
        }
#endif
/*---------- Do primary statment below here \/----------*/
    int times,runTimes,i;
    unsigned int num;

    for(fscanf(INPUT," %d",&runTimes);runTimes>0;runTimes = runTimes - 1){
        fscanf(INPUT," %u",&num);
        times = 0;
        for(i = 0 ; !i ; i = isAnagram(num) ){
            num = num + reverseInt(num);
            times = times + 1 ;
        }
        printf("%d %u\n",times,num);
    }
/*---------- Do primary statment above here /\----------*/
    #ifndef ONLINE_JUDGE/* If compiler isn't UVa's online judge */
        printf("--acm_10018 end here--\n");/* Print end of problem */
        fclose(fptIn);/* Close file */
    #endif
    return 0;
}/*End of main() function*/
/*---------- Do sub function statment below here /\----------*/
    unsigned int reverseInt(unsigned int num){
    unsigned int reverse=0;
    while(num>0){
        reverse = (reverse * 10) + (num % 10);
        num = num / 10;
    }
    return reverse;
}
int isAnagram(unsigned int num){
    if( num == reverseInt(num)){
        return 1;
    } else {
        return 0;
    }
}

/*---------- Do sub function statment above here \/----------*/
